#include "G4SystemOfUnits.hh"
#include "Randomize.hh"
#include "MyBaseGen.hh"

MyBaseGen::MyBaseGen()
{
    m_BoxLength = 30;
    m_BallRadius = 500;
}
MyBaseGen::~MyBaseGen(){}

G4ThreeVector MyBaseGen::ConvertArrayToV3(YAML::Node array)
{
    if (!array.IsDefined() || !array.IsSequence() || array.size() != 3)
        return G4ThreeVector(0., 0., 0.);
    return G4ThreeVector(array[0].as<double>(0.), array[1].as<double>(0.), array[2].as<double>(0.));
}

std::pair<G4ThreeVector, G4ThreeVector> MyBaseGen::GenPosAndMomDir()
{
    G4double theta = acos(2*(G4UniformRand()-0.5));
    G4double phi = 2 * G4UniformRand() * M_PI;
    G4double my_x = m_BoxLength * (G4UniformRand() - 0.5);
    G4double my_y = m_BoxLength * (G4UniformRand() - 0.5);

    std::pair<G4ThreeVector, G4ThreeVector> PosAndMomDir;

    PosAndMomDir.first = G4ThreeVector(-my_x * sin(phi) + my_y * cos(theta) * cos(phi) + m_BallRadius * sin(theta) * cos(phi),
                                      my_x * cos(phi) + my_y * cos(theta) * sin(phi) + m_BallRadius * sin(theta) * sin(phi),
                                      -my_y * sin(theta) + m_BallRadius * cos(theta)) * cm;
    PosAndMomDir.second = G4ThreeVector(-sin(theta) * cos(phi), -sin(theta) * sin(phi), -cos(theta));
    return PosAndMomDir;
}